package cn.xzqwjw.taskmanager.security.handler;

import cn.xzqwjw.taskmanager.common.customEnum.ResponseCodeEnum;
import cn.xzqwjw.taskmanager.domain.vo.ResponseVo;
import cn.xzqwjw.taskmanager.utils.ResponseUtil;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;

/**
 * 自定义Session过期时的错误输出格式，这里是输出成json
 *
 * @author rush
 */
public class SessionExpiredHandler implements SessionInformationExpiredStrategy {

  @Override
  public void onExpiredSessionDetected(SessionInformationExpiredEvent event) {
    String code = ResponseCodeEnum.BAD_REQUEST.getStatusCode();
    String message = "账号在另一地点登录，请重新登录！";
    ResponseUtil.writeJson(event.getResponse(), ResponseVo.error(code, message));
  }

}
